//
//  ZBZYPriceCell.swift
//  ANOA
//
//  Created by 邱仙凯 on 2022/4/6.
//  Copyright © 2025 aowang. All rights reserved.
//

import UIKit
 
import Kingfisher
class ZBZYPriceCell: TenderBaseCell {
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        
    
        
        
    }
    /// 三种模式   投标样式  销售招标带图标样式    销售招标不带图样式  --- withPicture 只有销售招标用到
    
    func makeConstrainsts(_ listType:TBandJPType = .TB,withPicture:Bool = true) {
        if listType == .TB {
            dingwei.isHidden = false
            btn1.snp.makeConstraints { (make) in
                make.left.equalTo(lab1)
                make.width.equalTo(60)
                make.height.equalTo(25)
                make.top.equalTo(lab1)
            }
            lab1.snp.makeConstraints { (make) in
                make.left.equalTo(self.contentView).offset(11)
                make.right.equalTo(self.contentView).offset(-15)
                make.top.equalTo(self.contentView).offset(6)
            }
            
            
            lab2.snp.makeConstraints { (make) in
                make.left.right.equalTo(lab1)
                make.top.equalTo(lab1.snp.bottom).offset(6)
            }
            
            dingwei.snp.makeConstraints { (make) in
                make.height.equalTo(15)
                make.width.equalTo(14)
                make.left.equalTo(lab1)
                make.top.equalTo(lab2.snp.bottom).offset(6)
            }
            
            lab3.snp.makeConstraints { (make) in
                make.left.equalTo(lab1)
                make.right.equalTo(self.contentView).offset(10)
                make.top.equalTo(dingwei)
            }
            
            lab4.snp.makeConstraints { (make) in
                make.left.equalTo(lab1)
                make.right.equalTo(oper_btn.snp.left).offset(-2)
                make.bottom.equalTo(self.contentView).offset(-10)
            }
            
            oper_btn.snp.makeConstraints { (make) in
                make.top.equalTo(lab3.snp.bottom).offset(2)
                make.width.equalTo(70)
                make.right.equalTo(self.contentView).offset(-15)
                make.height.equalTo(32)
                make.bottom.equalTo(self.contentView).offset(-5)
                
            }
        } else { // 竞拍
            dingwei.isHidden = true
            if withPicture {
                imageV.snp.makeConstraints { (make) in
                    make.left.equalTo(self.contentView).offset(12)
                    make.centerY.equalTo(self.contentView)
                    make.width.height.equalTo(95)
                }
                lab1.snp.makeConstraints { (make) in
                    make.left.equalTo(imageV.snp.right).offset(12)
                    make.right.equalTo(self.contentView).offset(-10)
                    make.top.equalTo(self.contentView).offset(12)
                    //                make.bottom.equalTo(self).offset(-100)
                }
                btn1.snp.makeConstraints { (make) in
                    make.left.equalTo(lab1)
                    make.width.equalTo(60)
                    make.height.equalTo(25)
                    make.top.equalTo(lab1.snp.bottom).offset(3)
                }
                chujiaLab.snp.makeConstraints { (make) in
                    make.centerY.equalTo(btn1)
                    make.right.equalTo(self.contentView).offset(-10)
                }
                
                lab2.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(btn1.snp.bottom).offset(3)
                }
                lab3.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(lab2.snp.bottom).offset(3)
                }
                
                lab4.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(lab3.snp.bottom).offset(3)
                    
                }
                oper_btn.snp.makeConstraints { (make) in
                    make.top.equalTo(lab4.snp.bottom).offset(2)
                    make.width.equalTo(70)
                    make.right.equalTo(self.contentView).offset(-15)
                    make.height.equalTo(32)
                    make.bottom.equalTo(self.contentView).offset(-5)
                }
            } else {
                
                lab1.snp.makeConstraints { (make) in
                    make.left.equalTo(self.contentView).offset(12)
                    make.right.equalTo(self.contentView).offset(-10)
                    make.top.equalTo(self.contentView).offset(12)
                    //                make.bottom.equalTo(self).offset(-100)
                }
                btn1.snp.makeConstraints { (make) in
                    make.left.equalTo(lab1)
                    make.width.equalTo(60)
                    make.height.equalTo(25)
                    make.top.equalTo(lab1.snp.bottom).offset(3)
                }
                chujiaLab.snp.makeConstraints { (make) in
                    make.centerY.equalTo(btn1)
                    make.right.equalTo(self.contentView).offset(-10)
                }
                
                lab2.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(btn1.snp.bottom).offset(3)
                }
                lab3.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(lab2.snp.bottom).offset(3)
                }
                
                lab4.snp.makeConstraints { (make) in
                    make.left.right.equalTo(lab1)
                    make.top.equalTo(lab3.snp.bottom).offset(3)
                    
                }
                oper_btn.snp.makeConstraints { (make) in
                    make.top.equalTo(lab4.snp.bottom).offset(2)
                    make.width.equalTo(70)
                    make.right.equalTo(self.contentView).offset(-15)
                    make.height.equalTo(32)
                    make.bottom.equalTo(self.contentView).offset(-5)
                }
            }
            
        }
        
        
        
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var one = ZtbContentModel(JSON:["":""])! {
        didSet {
           
                lab1.attributedText = NSAttributedString(string: "                \(one.zTbCompany.unwrap)", attributes: titleAttributes)
                
                var  lab2Str:String = ""
                if one.innerType! == .tbRecordKHW {
                    let cont = one.zContent.unwrap.isEmpty ? "" :"\n投标说明:\(one.zContent.unwrap)"
                    
                    
                    lab2Str = "出价:\(one.zPrice.unwrap)元\n联系人:\(one.zName.unwrap)     联系电话:\(one.zTel.unwrap)    \(cont)"
                } else {
                    lab2Str = "出价：\(one.zPrice.unwrap)元   \(one.zBidNum.unwrap)头   联系人：\(one.zName.unwrap) 电话:\(one.zTel.unwrap)"
                }
                lab2.attributedText = NSAttributedString(string: lab2Str, attributes: lab3Attributes)
                
                
                lab3.text = "    \(one.zCity.unwrap)    \(one.zCreateTm.unwrap)"
                
                oper_btn.setTitle("", for: .normal)
            
            var btnName = ""
            if one.zStatus.unwrap == "1" {
                btnName =  "已成交"
                oper_btn.setTitle("车辆信息", for: .normal)

            } else if one.zStatus.unwrap == "0" {
                btnName =  "未成交"
                oper_btn.setTitle("", for: .normal)

            } else {
                btnName =  "已弃拍"
                oper_btn.setTitle("", for: .normal)
            }
             btn1.setTitle(btnName, for: .normal)
                lab4.text = one.zPriceRank.unwrap
 
            
        }
    }
    @objc func btn2Action(sender:UIButton) {
        if let closure = btn2Closure {
            closure(sender,sender.titleLabel!.text.unwrap)
        }
    }
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
